package com.njtoyo.taxi.admin.rest.controller.local_service.merchant;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.rest.presenter.local_service.merchant.LifeMerchantAccountPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.merchant.LifeMerchantAccountAddWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.merchant.LifeMerchantAccountUpdateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.local_service.merchant.LifeMerchantAccountWrapper;
import com.njtoyo.taxi.admin.service.local_service.merchant.MerchantAccountService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@RestController
@Api(value = "商户账号管理", tags = "商户账号管理")
@RequestMapping("local-service/merchant/account")
public class MerchantAccountController {

    @Autowired
    private MerchantAccountService merchantAccountService;

    @GetMapping("")
    @ApiOperation(value = "商户账号列表", notes = "商户账号列表,权限：life_merchant_account_list")
    @PermissionScope(names = {"life_merchant_account_list"})
    RestResult<Page<LifeMerchantAccountPresenter>> getPage(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser,
                                                           @Valid LifeMerchantAccountWrapper wrapper) {
        return merchantAccountService.getPage(adminUser, wrapper);
    }

    @PostMapping("")
    @ApiOperation(value = "商户账号添加", notes = "商户账号添加,权限：life_merchant_account_add")
    @PermissionScope(names = {"life_merchant_account_add"})
    RestResult add(@Valid @RequestBody LifeMerchantAccountAddWrapper wrapper) {
        return merchantAccountService.add(wrapper);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "商家账号更改状态", notes = "商家账号更改状态,权限：life_merchant_account_update")
    @PermissionScope(names = {"life_merchant_account_update"})
    RestResult update(@PathVariable("id") Long id,
                      @Valid @RequestBody LifeMerchantAccountUpdateWrapper wrapper) {
        return merchantAccountService.update(id, wrapper);
    }
}
